@extends('backstage.layout.master')
@include('UEditor::head')
@section('title', '添加公告')
@section('style')
    <style>
        .ace-file-input input[type=file] {
            position: static;
        }
        .ace-nav {
            height: 10px;
        }
        .icon-animated-bell{
            margin-top: 13px;
        }
    </style>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>
            <li class="active">
                <a href="backstage/announcements/list">公告列表</a>
            </li>
            <li>
                添加公告
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        添加公告
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <form id="myform" class="form-horizontal" role="form" action="backstage/announcements/add" method="post" enctype="multipart/form-data">
                            <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                            <div class="form-group resource_form {{$errors->first('announcement_content')!=""?'has-error':''}}">
                                <label class="col-sm-4 control-label no-padding-right"> 公告内容 </label>
                                <div class="col-sm-4">
                                    <input type="text" name="announcement_content" value="{{old('announcement_content')}}" placeholder="公告内容"
                                           class="width-100">
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline">{{$errors->first('announcement_content')}} </div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group ">
                                <label class="col-sm-4 control-label no-padding-right"> 类型选择 </label>
                                <div class="col-sm-4">
                                    <select name="announcement_type" class="form-control" id="form-field-select-1">
                                        <option @if(old('announcement_type') == 1)selected @endif value="1">默认（不进行任何跳转）</option>
                                        <option @if(old('announcement_type') == 2)selected @endif value="2">跳转公告详情页面</option>
                                    </select>
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline">{{$errors->first('announcement_type')}} </div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('announcement_begin_time')!=""?'has-error':''}}">
                                <label class="col-sm-4 control-label no-padding-right">开始时间</label>
                                <div class="col-sm-4">
                                    <input type="date" id="begin" name="announcement_begin_time" class="form-control datepicker" value="{{old("announcement_begin_time")}}"/>
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('announcement_begin_time')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('announcement_end_time')!=""?'has-error':''}}">
                                <label class="col-sm-4 control-label no-padding-right">结束时间</label>
                                <div class="col-sm-4">
                                    <input type="date" id="end" name="announcement_end_time" class="form-control datepicker" value="{{old("announcement_end_time")}}"/>
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('announcement_end_time')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group  {{$errors->first('is_send_message')!=""?'has-error':''}}">
                                <label class="col-sm-4 control-label no-padding-right">
                                    是否推送系统消息</label>

                                <div class="col-sm-4">
                                    <input type="radio" name="is_send_message" value="0" id="hide" checked> <label
                                            for="hide">否</label> <input type="radio" name="is_send_message"
                                                                        value="1" id="show"> <label
                                            for="show">是</label>
                                </div>
                                <div class="col-sm-4">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('is_send_message')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group" id="content_id" style="display: none;">
                                <div class="col-sm-7 col-md-offset-5">填写公告具体内容</div>
                                <div class="col-sm-4">
                                    <script id="container" name="announcement_detail_content" type="text/plain">
                                        {!! old('announcement_detail_content') !!}
                                    </script>
                                </div>
                            </div>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-5 col-md-7">
                                    <button class="btn btn-info" type="submit" onclick="return confirm('确认保存吗？');">
                                        <i class="icon-ok bigger-110"></i>
                                        保存
                                    </button>

                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn" type="reset">
                                        <i class="icon-undo bigger-110"></i>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div><!-- /.col -->
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function(){
            $("#begin").change(function() {
                $("#end").attr("min", $(this).val());
            });
            $("#end").change(function() {
                $("#begin").attr("max", $(this).val());
            });
            var editor = new UE.ui.Editor({
                initialFrameWidth: 1000,
                initialFrameHeight: 400
            });
            $('#container').css("align", "center");
            editor.render("container");
            var ue = UE.getEditor('container');
            ue.ready(function () {
                $("#edui1").addClass("col-sm-offset-2 ");
                $(".col-sm-4").show();
                $(".form-actions").show();
                ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.
            });
            var announcement_type = $('#form-field-select-1').val();
            change_content_show(announcement_type);
            $('#form-field-select-1').change(function(){
                var announcement_type = $(this).val();
                change_content_show(announcement_type);
            });
        });
        function change_content_show(announcement_type){
            if(announcement_type == 2){
                $('#content_id').show();
            }else{
                $('#content_id').hide();
            }
        }
    </script>
@stop
